<?php


namespace app\common\lib;
use think\Container;
class Export
{
    /** socket 返回码标示  */
    public static $socket_prompt_cmd = 100;             //消息提示
    public static $socket_single_chat_cmd = 101;        //单人聊天
    public static $socket_team_chat_cmd = 102;          //群组聊天
    public static $socket_match_cmd = 103;              //在线匹配

    /** 正确返回信息 */
    public static function exp_ok($data=[]){
        $return_data = [
            "error"=>ErrorCode::$NO_ERROR,
            "message"=>"成功",
        ];
        if($data){
            !is_array($data) && $data = [$data];
            $return_data = array_merge($return_data,$data);
        }
        echo json_encode($return_data,JSON_UNESCAPED_UNICODE);
    }
    /** 错误返回信息 */
    public static function exp_err($msg,$code=0){
        $code == 0 && $code = ErrorCode::$USUAL_ERROR;
        $return_data = [
            "error"=>$code,
            "message"=>$msg,
        ];
        echo json_encode($return_data,JSON_UNESCAPED_UNICODE);
    }

    /** 正确返回信息  */
    public static function socket_exp_ok($fd,$cmd=0,$data=[]){
        $return_data = [
            "error"=>ErrorCode::$NO_ERROR,
            "msg"=>"成功",
            "cmd"=>$cmd,
        ];
        if($data){
            !is_array($data) && $data = [$data];
            $return_data = array_merge($return_data,$data);
        }
        Container::get('swoole')->push($fd, json_encode($return_data,JSON_UNESCAPED_UNICODE));
    }
    /** 错误返回信息 */
    public static function socket_exp_err($fd,$msg,$code=0){
        $code == 0 && $code = ErrorCode::$USUAL_ERROR;
        $return_data = [
            "error"=>$code,
            "message"=>$msg,
        ];
        Container::get('swoole')->push($fd, json_encode($return_data,JSON_UNESCAPED_UNICODE));
    }
}